package com.example.administrator.myapplication;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;


public class MainActivity extends Activity {


    private TextView zhuche;
    private TextView wangji;
    private EditText username_et;
    private EditText password_et;
    private Button login;
    private String username,password;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.denglu);
        zhuche = (TextView) findViewById(R.id.zhuchentV);
        wangji = (TextView) findViewById(R.id.wangjitV);
        username_et=(EditText) findViewById(R.id.username);
        password_et=(EditText) findViewById(R.id.password);
        login=(Button) findViewById(R.id.login);



        new Thread() {
            @Override
            public void run() {
                super.run();

                //1. 创建httpclient对象
                HttpClient httpClient = new DefaultHttpClient();
                //2. 创建请求方式
                HttpGet httpGet = new HttpGet("http://api.zhaibao.cn/login?");

                try {
                    HttpResponse httpResponse = httpClient.execute(httpGet);
                    if (httpResponse.getStatusLine().getStatusCode() == 200) {
                        HttpEntity httpEntity = httpResponse.getEntity();

                        String resault = EntityUtils.toString(httpEntity);

                        Log.e("resaul===>", resault);
                    }

                } catch (IOException e) {

                }

            }
        }.start();


        zhuche.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, zhuce.class);
                MainActivity.this.startActivity(intent);
            }
        });


        wangji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, ZhaoHuiMiMa.class);
                MainActivity.this.startActivity(intent);
            }
        });



        login.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                username = username_et.getText().toString();
                password = password_et.getText().toString();


                //现在默认用户名 是 123 密码 123
                if (username.equals("123")&&password.equals(password)) {

                    Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();

                    Intent intent2=new Intent();
                    intent2.setClass(getApplicationContext(), Welcome.class);
                    startActivity(intent2);


                }else {

                    Toast.makeText(getApplicationContext(), "用户名或者是密码错误", Toast.LENGTH_SHORT).show();
                }


            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}